/*
 * Description: description of series.js
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Dongxu.Ni
 * Date: 2020/4/15 0:24
 */

import { seriesList } from '../../api/quote/series'

const state = {
  seriesCollects: []
}

const getters = {
  getSeriesCollects: state => state.seriesCollects,
  getSeriesById: state => seriesId => {
    return state.seriesCollects.find(series => series.seriesId === seriesId)
  }
}

const mutations = {
  SET_SERIES_COLLECTS: (state, seriesCollects) => {
    state.seriesCollects = seriesCollects
  }
}

const actions = {
  initSeriesCollects({ commit }) {
    return new Promise((resolve, reject) => {
      seriesList({})
        .then(response => {
          commit('SET_SERIES_COLLECTS', response.data)
          resolve()
        })
        .catch(err => reject(err))
    })
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
